package org.aplikator.server.descriptor;

import org.aplikator.client.shared.descriptor.RepeatedFormDTO;
import org.aplikator.client.shared.descriptor.WidgetDTO;
import org.aplikator.server.Context;

public class RepeatedForm extends WidgetPropertyDescriptorBase<Integer> {

    private View view;

    public RepeatedForm(Collection<? extends Entity> property, View view) {
        super (property);
        this.view = view;
    }

    @Override
    public WidgetDTO getWidgetDescriptor(Context ctx) {
        RepeatedFormDTO desc = new RepeatedFormDTO(getProperty().clientClone(ctx), view.getViewDTO(ctx));
        desc.setSize(getSize());
        desc.setEnabled(isEnabled());
        return desc;
    }

    @Override
    public void registerProperties(Form form) {
        // form.addProperty(property);
    }

    public static RepeatedForm repeated(Collection<? extends Entity> property){
        return new RepeatedForm(property, property.referredEntity.view());
    }

    public static RepeatedForm repeated(Collection<? extends Entity> property, View view){
        return new RepeatedForm(property, view);
    }
}
